<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Authen extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct() {
    	parent::__construct();
		$this->load->database();
		$this->load->model('authen_model');
		$this->load->helper('url');


	}
	public function index()
	{
		//$this->load->view('v_test');

	}
	function logout(){

		if($_SESSION['username'] != ""){
			session_destroy();
		}
		
		redirect(base_url()."authen/login");


	}
	function login(){

        $data['loginfail'] = FALSE;
		$this->load->view('authen/v_login',$data);
	}
	function checklogin(){

		$username = $this->input->post('username');
		$password = $this->input->post('password');

		$check = $this->authen_model->checkLogin($username,$password);
		if($check){

			//$_SESSION['username'] = $username;
			//echo base_url();
			redirect(base_url()."test/");
		}
		else{
            $data['loginfail'] = TRUE;
			$this->load->view('authen/v_login',$data);
		}

	}
}
?>